package com.yowasa.xiuxian.entity.bo.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yowasa.xiuxian.util.RandomUtil;
import com.yowasa.xiuxian.util.StrUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * 用户属性
 */
@Data
public class UserAttr implements Serializable {

    /**
     * 体质
     */
    private int con;

    /**
     * 力量
     */
    private int str;

    /**
     * 气感
     */
    private int ints;

    /**
     * 敏捷
     */
    private int dex;

    /**
     * 仙缘
     */
    private int luc;

    /**
     * 悟性
     */
    private int und;

    @JsonIgnore
    public String getDesc() {
        String msg = "体质:${con} 力量:${str} 气感:${ints}\n" +
                "敏捷:${dex} 仙缘:${luc} 悟性:${und}";
        return StrUtil.processTemplate(msg, this);
    }


    public static UserAttr genAttr() {
        UserAttr userAttr = new UserAttr();
        userAttr.setCon(RandomUtil.genRandomAttr());
        userAttr.setDex(RandomUtil.genRandomAttr());
        userAttr.setInts(RandomUtil.genRandomAttr());
        userAttr.setLuc(RandomUtil.genRandomAttr());
        userAttr.setStr(RandomUtil.genRandomAttr());
        userAttr.setUnd(RandomUtil.genRandomAttr());
        return userAttr;
    }

    //全属性提升
    public void upFull(int n) {
        this.setCon(Math.min(this.getCon() + 2 * n, 100));
        this.setDex(Math.min(this.getDex() + 2 * n, 100));
        this.setInts(Math.min(this.getInts() + 2 * n, 100));
        this.setLuc(Math.min(this.getLuc() + 2 * n, 100));
        this.setStr(Math.min(this.getStr() + 2 * n, 100));
        this.setUnd(Math.min(this.getUnd() + 2 * n, 100));
    }


}
